<?php 
include("head.php"); 
include_once("../Adminincludes/config.php");
include_once("parsetemplate.php");
include_once("paging_function.php");
$filename='newsletter.html';
$lim=$adminpagelimit;
?>

<script language="JavaScript">
function checkAll(field)
{
for (i = 0; i < field.length; i++)
{
	if(field[i].name=='check1[]')
	{
	field[i].checked = true ;
	}
}	
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
{
	if(field[i].name=='check1[]')
	{
	field[i].checked = false ;
	}
}
}
function chkMail()
{
if(document.getElementById("eadd").value=='')
return false;
}

</script>	  
<script>
function changeUrl(indexalpha)
{
var url='mailmgt.php?index='+indexalpha;
window.location=url;
}
</script>
<?php  
if(isset($_REQUEST['esend']))
	{
// --------------------------------------------------------------------------------------------
	$maillist=$_REQUEST['emailaddto'];
		$check4=explode(",",$maillist);					
		$no=count($check4);
		for($i=0;$i<$no;$i++)
		{	$email_var=$check4[$i];
			$headers  = 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
			$headers .= "From:Admobweb\r\n";			
    			$subject = $_REQUEST['eadd'] ;
    			$message = $_REQUEST['sbody'] ;
	$NewsLetterMailcontent=loadFile($filename);
	$NewsLetterEmail=$res['Email'];
	$Title_="Your Newsletter Copy";
	$Mailcontebt="Thanks for subscribing! You Will receive
	mailing list Free content for your newsletter - Admobweb ";
	$Thanks="Thanks From Admobweb Team.";
	$message1='<html><head></head><body><p>&nbsp;&nbsp;&nbsp;&nbsp;'.$message.'</p></body></html>';
	$NewsLetterMailcontent = str_replace("[Title]", $subject, $NewsLetterMailcontent);
	$NewsLetterMailcontent = str_replace("[MAILCONTENT]", $message, $NewsLetterMailcontent);
	$NewsLetterMailcontent = str_replace("[THANKS]", $Thanks, $NewsLetterMailcontent);				
			@mail($email_var,$Title_,$NewsLetterMailcontent,$headers);
				$var_eztz="";			
		}
		echo '<p style="color:#FF0000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Thank you mail successfully send</strong></p>';
	}
?>





<?php
if(isset($_GET['page']))
		{		
			$page = $_GET['page'];
		}
	else
		{
			$page = 0;
		}
       $limit=$lim;

	$sql="SELECT * FROM ".SITEUSERS." WHERE 1";

	if($_REQUEST['uname']!='' && isset($_REQUEST['uname']))
		
		{
		
			$param="uname=".$_REQUEST['uname'];
			$sql.=" AND username like'".$_REQUEST['uname']."%'";
				
		}
		if($_REQUEST['email']!='' && isset($_REQUEST['email']))
		
		{
		
			$param="email=".$_REQUEST['email'];
			$sql.=" AND email like'".$_REQUEST['email']."%'";
					
		}
		if($_REQUEST['index']!='' && isset($_REQUEST['index']))
		
		{
		
			$param="index=".$_REQUEST['index'];
			$sql.=" AND username like'".$_REQUEST['index']."%'";
					
		}
		
		else
		{
		$sql.=" ORDER BY siteuserId DESC ";
		}
		$sql.=" limit $page,$limit";
		
		$query=mysql_query($sql);
		?>
	
<table width="100%" border="0" cellspacing="0" cellpadding="3" class="tabbod" bgcolor="#F3F3F3">
<form name="mail" method="POST" action="">
		<tr>
		
		<td height="15" colspan="5" align="center" style="color:#000000;font-size:12px;"><strong>OPTIOLAL NEWS LETTER MANAGEMENT</strong><p><strong style="font-weight: 400">Click on the alphabets to browse User </strong>Name<strong style="font-weight: 400"><br>&nbsp;</strong></p><?php include_once("search_alphabets.php");?></td>		
		</tr>
		<tr><td colspan="5">&nbsp;</td></tr>
		<tr>
			<td colspan="5">
				<table>
					<tr>
						<td>Search By Name&nbsp;&nbsp;<input type="text" size="10" value="<?php echo $_REQUEST['uname'];?>" name="uname"></td>
						<td>&nbsp;&nbsp;&nbsp;&nbsp;By Email&nbsp;&nbsp;<input type="text" size="10" value="<?php echo $_REQUEST['email'];?>" name="email">&nbsp;&nbsp;&nbsp;&nbsp;</td> 
						<td><input type="submit" name="submitt" value="Search"></td>
					</tr>
				</table>
			</td>
		</tr>

		<tr bgcolor="#6F8DBC">
		<td width="2%">&nbsp;</td>
		<td width="20%" align="left" style="color:#ffffff;font-size:13px;"><strong>User Name</strong></td>
		<td width="47%" align="left" style="color:#ffffff;font-size:13px;">
		  <strong>Email</strong> </td>
<td width="30%" align="right" style="color:#ffffff;font-size:12px;"><input type=button name="CheckAll" value="Check All" onClick="checkAll(this.form);" style="bgcolor:#6F8DBC;">/
<input type=button name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(this.form);" style="bgcolor:#6F8DBC;"></td>
<td width="1%">&nbsp;</td>
		</tr>
<?php 
		 $count=1;

		 $loop=0;
		
		while($fetch=mysql_fetch_array($query))
		{
			$loop++;


		if($loop == 1) $bgcolor = "#F0F0FF";



		else $bgcolor = "#CCCCFF";
			?>
			<tr bgcolor="<?php echo $bgcolor; ?>">
			<td width="2%">&nbsp;</td>
			<td align="left"><strong><?php echo $fetch['username'];?></strong></td>
			<td><?php echo $fetch['email'];?></td>
			<td height="25" valign="middle" align="right"><input type="checkbox" name="check1[]" id="chk<?php echo $count; ?>" value="<?php echo $fetch['email'];?>"></td>
			<td>&nbsp;</td>
			</tr>	
	  <?php
		$count++;
		if($loop == 2)
			{
				$loop = 0;
			}	
		 }?>
		
             <tr>
		<td width="2%">&nbsp;</td>
		<td>&nbsp;</td>
		<td align="center" >&nbsp;</td>
		<td align="right">


		<input type="submit" name="sub_mail" value="Write Mail" onclick=""></td>
	<td></td>
	    </tr>
<TR>
<TD colspan="5" align="center"><?php echo paging($sql,$page,$limit,'');?></TD>
</TR>
</form>
<tr> <td colspan="5">

<?php 

if(isset($_POST['sub_mail']))
{?>
<form name="email" action="" method="POST">
<table align="left" border="0" bgcolor="#F3F3F3" id="sendmail">
<TR>
<TD height="39">
<font size="2" face="Times" color="black">E-mail Address:</font></td>
<td>
<?php				
				$check2=$_REQUEST['check1'];
				if($check2!="")
				{
				$var_mail1=implode(", ",$check2);
				}
				?>
<textarea rows="0" cols="80" name="emailaddto" id="emailaddto" readonly=""><?php echo $var_mail1;?></textarea>
</TD>
</TR>
<tr>
<TD>
<font size="2" face="Times" color="black">Subject:</font></td>
<td>
<textarea rows="0" cols="80" name="eadd" id="eadd">
</textarea>
</TD>
</TR>
<tr>
<TD>
<font size="2" face="Times" color="black">Subject Body:</font></td>
<td>
<textarea rows="10" cols="80" name="sbody">
</textarea>
</TD>
</tr>
<tr>
<td></td>
<TD>
<input type="submit" name="esend" value="send" onclick="return chkMail();">			
<input type="submit" name="ecancel" value="cancel">
</TD>
</tr>

</table>
</form>
<?php } 
////////////////////////////////


?>
</td></tr></table>

<?php include_once("foot.php");?>
